package cn.kgc.controller.logic.desktop;

import cn.kgc.pojo.*;
import cn.kgc.service.desktop.TaskService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/sfc")
public class TaskController {
    @Resource
    private TaskService ts;

    //按条件查询，显示数据
    @RequestMapping("/sell")
    @ResponseBody
    public String selltask(Integer jt_id, String begintime, String name, String state, Integer currentPage, Integer pageSize) {
//        System.out.println("state ============ " + state);
        PageHelper.startPage(currentPage, pageSize);
        Page<Leaveuser> leaveapplies = ts.selLeave(jt_id, begintime, name, state,null);
//        leaveapplies.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(leaveapplies);
//        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selbyid")
    private String selbyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Leaveuser> list = ts.selLeave(null, null, null, null, id);
//        System.out.println("list =+++++++++++++++++++++++++++++++++++++++++ " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-tasklook";
    }

    //审核
    @RequestMapping("/upd")
    @ResponseBody
    public int upd(Integer id, Integer state) {
        int b = ts.updLeave(id, state);
        return b;
    }

    /**
     * 车辆申请查询
     *
     * @param usetime
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/sellCars")
    @ResponseBody
    public String sellCars(String usetime,String name,String state, Integer currentPage, Integer pageSize) {
//        System.out.println("begintime ============ " + begintime);
        PageHelper.startPage(currentPage, pageSize);
        Page<Cars> cars = ts.selCara(usetime,name,state,null);
        cars.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(cars);
        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selCarbyid")
    private String selCarbyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Cars> list = ts.selCara(null,null,null,id);
        System.out.println("list = " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-carlook";
    }

    //审核
    @RequestMapping("/updCar")
    @ResponseBody
    public int updCars(Integer id, Integer state, String approver) {
        int b = ts.updCar(id, state, approver);
        return b;
    }

    /**
     * 用章申请查询
     *
     * @param yzTime
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/sellChapt")
    @ResponseBody
    public String sellChapt(String yzTime,String name,String state, Integer currentPage, Integer pageSize) {
//        System.out.println("begintime ============ " + begintime);
        PageHelper.startPage(currentPage, pageSize);
        Page<Chap> cars = ts.selChapt(yzTime,name,state,null);
        cars.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(cars);
        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selChaptbyid")
    private String selChaptbyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Chap> list = ts.selChapt(null,null,null,id);
        System.out.println("list = " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-chaptlook";
    }

    //审核
    @RequestMapping("/updChapt")
    @ResponseBody
    public int updChapt(Integer id, Integer state, String approver) {
        int b = ts.updChapt(id, state, approver);
        return b;
    }

    /**
     * 会议室申请查询
     *
     * @param ydtime
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/sellMeet")
    @ResponseBody
    public String sellMeet(String ydtime,String name,String state, Integer currentPage, Integer pageSize) {
//        System.out.println("begintime ============ " + begintime);
        PageHelper.startPage(currentPage, pageSize);
        Page<Meet> cars = ts.selMeet(ydtime,name,state,null);
        cars.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(cars);
        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selMeetbyid")
    private String selMeetbyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Meet> list = ts.selMeet(null,null,null,id);
        System.out.println("list = " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-meetlook";
    }

    //审核
    @RequestMapping("/updMeet")
    @ResponseBody
    public int updMeet(Integer id, Integer state, String approver) {
        int b = ts.updMeet(id, state, approver);
        return b;
    }

    /**
     * 用章申请查询
     *
     * @param createTime
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/sellBusin")
    @ResponseBody
    public String sellBusin(String createTime,String name,String state, Integer currentPage, Integer pageSize) {
//        System.out.println("begintime ============ " + begintime);
        PageHelper.startPage(currentPage, pageSize);
        Page<Busin> cars = ts.selBusin(createTime,name,state,null);
        cars.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(cars);
        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selBusinbyid")
    private String selBusinbyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Busin> list = ts.selBusin(null,null,null,id);
        System.out.println("list = " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-businlook";
    }

    //审核
    @RequestMapping("/updBusin")
    @ResponseBody
    public int updBusin(Integer id, Integer state, String approver) {
        int b = ts.updBusin(id, state, approver);
        return b;
    }

    /**
     * 用章申请查询
     *
     * @param begintime
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/sellTrre")
    @ResponseBody
    public String sellTrre(Integer jt_id,String begintime,String name,String state, Integer currentPage, Integer pageSize) {
//        System.out.println("begintime ============ " + begintime);
        PageHelper.startPage(currentPage, pageSize);
        Page<Trre> cars = ts.selTrre(jt_id,begintime,name,state,null);
        cars.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(cars);
        System.out.println("pageInfo =!!!!!!!!!!!!! " + pageInfo);
        return JSON.toJSONString(pageInfo);
    }


    //弹出层渲染数据
    @RequestMapping("/selTrrebyid")
    private String selTrrebyid(Integer id, Model model) {
//        System.out.println("id =******************** " + id);
        List<Trre> list = ts.selTrre(null,null,null,null,id);
        System.out.println("list = " + list);
        model.addAttribute("list", list);
        return "/desktop/sfc-trrelook";
    }

    //审核
    @RequestMapping("/updTrre")
    @ResponseBody
    public int updTrre(Integer id, Integer state, String approver) {
        int b = ts.updTrre(id, state, approver);
        return b;
    }
}